package com.smarthome.web.property.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.smarthome.common.tools.excel.ReportExportService;
import com.smarthome.domain.bean.ShOrders;

@Controller
@RequestMapping(value = "/testController")
public class TestController {

    @RequestMapping(value = "/downloadExcel", method = { RequestMethod.GET })
    public void downloadExcel(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String title = "测试excel导出";
        List<String> headerNames = new ArrayList<String>();
        headerNames.add("订单号");
        headerNames.add("快递公司");
        headerNames.add("寄件人姓名");
        headerNames.add("寄件人电话");
        headerNames.add("寄件人地址");
        headerNames.add("发件人姓名");
        headerNames.add("发件人电话");
        headerNames.add("发件人地址");
        headerNames.add("寄件时间");
        List<String> cellNames = new ArrayList<String>();
        cellNames.add("id");
        cellNames.add("companyName");
        cellNames.add("srcAccountName");
        cellNames.add("srcMobile");
        cellNames.add("srcAreaDetail");
        cellNames.add("desAccountName");
        cellNames.add("desMobile");
        cellNames.add("desAreaDetail");
        cellNames.add("gmtCreate");
        List<Object> datas = new ArrayList<Object>();
        ShOrders order = new ShOrders();
        order.setId(20160326001L);
        order.setCompanyName("顺丰快递-丽都花园站");
        order.setSrcAccountName("张三");
        order.setSrcMobile("13821341121");
        order.setSrcAreaDetail("成都市东风大街27号丽都花园三栋1单元1103室");
        order.setDesAccountName("李四");
        order.setDesMobile("18233120912");
        order.setDesAreaDetail("广州市花园路33号滨江世纪城一栋4单元1203室");
        order.setGmtCreate(new Date());
        datas.add(order);
        new ReportExportService().doExportAndDownload(title, headerNames, cellNames, datas, response);
    }
}
